﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace WFBASE
{
    public class WFXML
    {
        public static XmlDocument LoadXml(string xml)
        {
           // return new XmlDocument().LoadXml(xml);
            return null;
        }

        #region 取得XML中的值
        public static string GetValue(XmlDocument xd, string xpath)
        {
            try
            {
                return xd.SelectSingleNode(xpath).InnerText;
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        public static string GetValue(string xmlString, string xpath)
        {
            return GetValue(LoadXml(xmlString), xpath);
        }
        #endregion

        #region 取得XML中的屬性
        public static string GetAttribute(XmlDocument xd, string xpath, string attrName)
        {
            try
            {
                return xd.SelectSingleNode(xpath).Attributes[attrName].ToString();
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        public static string GetAttribute(string xmlString, string xpath, string attrName)
        {
            return GetAttribute(LoadXml(xmlString),xpath,attrName);
        }
        #endregion

        #region JSON轉化為XML
        public static string Json2Xml(string jsonString)
        {
            return "";//xml string
        }
        #endregion
    }
}
